﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyCocos2D
{
    public class CCSprite : CCGameObject
    {
        private string ImgName;
        public string ImageName
        {
            get { return ImgName; }
            set { ImgName = value; }
        }

        private Image Img;
        public Image Image
        {
            get { return Img; }
            set { Img = value; }
        }

        public CCSprite(string fileName) : base()
        {
            Img = new Bitmap(fileName);
            ImgName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
        }

        public override bool getObject(Point p)
        {
            if (Position.X < p.X && p.X < Position.X + Img.Width &&
                Position.Y < p.Y && p.Y < Position.Y + Img.Height)
            {
                return true;
            }

            return false;
        }

        public override string serialineCPP()
        {
            string s = "";
            s += String.Format("\t{0} = CCSprite::create(\"{1}\");\n\t{0}->setPosition(ccp({2}, {3}));\n", Name, ImgName, Position.X, Position.Y);
            return s;
        }

        public override string serialineH()
        {
            string s = "";
            s += String.Format("\t\tCCSprite *{0};\n", Name);
            return s;
        }

        public override void Draw(Graphics g)
        {
            Point point = new Point();
            point.X = Position.X;
            point.Y = Position.Y;
            g.DrawImage(Img, point);
        }
    }
}
